Imports Microsoft.VisualBasic
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.Data
Imports DataAccesGenerales
Imports DataAcces

Public Class DataAccesEspaciosConfinados
  Private Const consTimeOut As Integer = 0 

    ''' <summary>
    ''' Funcion para Insertar un regristro en la tabla Espacios_Confinados
    ''' </summary>
   Public Function Espacios_Confinados_InsertarModificar(pnidDocumento As Long, pfecha_Inicio As String, pfecha_Fin As String, pnidEmpEmisora As Long, pnidEmpEjecutora As Long, parea As String, pubicacion As String, pproposito As String, pnum_Permiso As Long, poxigeno As Double, phidrocarburos As Double, pgasesToxicos As Double, pprueba_API As String, pprueba_Contratista As String, psuperintendente As String, presponsable As String, pautorizado_API As String, pFecha_Termino As String, paprobado As Integer, pejecutor As String, pobservaciones As String) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosInsertarModificar"
          oraCommandDocumentos.Parameters.Add("pnidDocumento", pnidDocumento)
          oraCommandDocumentos.Parameters.Add("pfecha_Inicio", pfecha_Inicio)
          oraCommandDocumentos.Parameters.Add("pfecha_Fin", pfecha_Fin)
          oraCommandDocumentos.Parameters.Add("pnidEmpEmisora", pnidEmpEmisora)
          oraCommandDocumentos.Parameters.Add("pnidEmpEjecutora", pnidEmpEjecutora)
          oraCommandDocumentos.Parameters.Add("parea", parea)
          oraCommandDocumentos.Parameters.Add("pubicacion", pubicacion)
          oraCommandDocumentos.Parameters.Add("pproposito", pproposito)
          oraCommandDocumentos.Parameters.Add("pnum_Permiso", pnum_Permiso)
          oraCommandDocumentos.Parameters.Add("poxigeno", poxigeno)
          oraCommandDocumentos.Parameters.Add("phidrocarburos", phidrocarburos)
          oraCommandDocumentos.Parameters.Add("pgasesToxicos", pgasesToxicos)
          oraCommandDocumentos.Parameters.Add("pprueba_API", pprueba_API)
          oraCommandDocumentos.Parameters.Add("pprueba_Contratista", pprueba_Contratista)
          oraCommandDocumentos.Parameters.Add("psuperintendente", psuperintendente)
          oraCommandDocumentos.Parameters.Add("presponsable", presponsable)
          oraCommandDocumentos.Parameters.Add("pautorizado_API", pautorizado_API)
          oraCommandDocumentos.Parameters.Add("pFecha_Termino", pFecha_Termino)
          oraCommandDocumentos.Parameters.Add("paprobado", paprobado)
          oraCommandDocumentos.Parameters.Add("pejecutor", pejecutor)
          oraCommandDocumentos.Parameters.Add("pobservaciones", pobservaciones)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
    ''' <summary>
    ''' Funcion para consultar un registro de la tabla Espacios_Confinados
    ''' </summary>
    ''' <param name="pNidDocumento">numero de documento</param>
    ''' <returns>DataTable</returns>
    ''' <remarks></remarks>
   Public Function Espacios_Confinados_Consultar(pNidDocumento As Long) As DataTable
        Dim dtResultado As New DataTable("Espacios_ConfinadosConsulta")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosConsultar"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para generar la cadena XML Chilkat del documento de la tabla Espacios_Confinados
    ''' </summary>
    ''' <param name="nidDocumento"> numero del documento</param>
    ''' <returns>Chilkat.Xml</returns>
    ''' <remarks></remarks>
   Public Function Espacios_Confinados_CadenaOriginalXMLChilkat(nidDocumento As Long) As Chilkat.Xml
        Dim detalleDataSet As New DataSet("DatosEspacios_Confinados")
        Try
      detalleDataSet = Espacios_Confinados_DetalleXML(nidDocumento)
            'En esta parte van las tablas obtenidas en la consulta anterior
            'separadas dependiendo del reporte a crear, ejemplo:
            detalleDataSet.Tables(0).TableName = "Informacion del Tramite"
            detalleDataSet.Tables(1).TableName = "Datos Espacios_Confinados"
            detalleDataSet.Tables(2).TableName = "Archivos Anexos"
            detalleDataSet.Tables(3).TableName = "Incidencias"

            Dim xml As New Chilkat.Xml
            xml.LoadXml(detalleDataSet.GetXml())
            Return xml 'detalleDataSet.GetXml()
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    ''' <summary>
    ''' Funcion para consultar el detalle del documento de la tabla Espacios_Confinados
    ''' </summary>
    ''' <param name="pNidDocumento">numero del documento</param>
    ''' <returns>DataSet</returns>
    ''' <remarks></remarks>
   Public Function Espacios_Confinados_DetalleXML(pNidDocumento As Long) As DataSet
        Dim dsDetalle As New DataSet("Espacios_ConfinadosDetalle")
        Dim pTransaccion As Byte = 0
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosDetalleXML"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    'En esta parte es para los cursores necesario 
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pEncabezado", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pDatos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pAnexos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pIncidencias", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    'pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    oraDataAdapter.Fill(dsDetalle)
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dsDetalle
    End Function
  
   Public Function Espacios_Confinados_DatosBase() As DataTable
        Dim dtResultado As New DataTable("Espacios_ConfinadosConsulta")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosDatosBase"
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para Insertar un regristro en la tabla Espacios_Confinados
    ''' </summary>
   Public Function Espacios_Confinados_Insertar(pnidDocumento As Long, pfecha_Inicio As String, pfecha_Fin As String, pnidEmpEmisora As Long, pnidEmpEjecutora As Long, parea As String, pubicacion As String, pproposito As String, pnum_Permiso As Long, poxigeno As Double, phidrocarburos As Double, pgasesToxicos As Double, pprueba_API As String, pprueba_Contratista As String, psuperintendente As String, presponsable As String, pautorizado_API As String, pFecha_Termino As String, paprobado As Integer, pejecutor As String, pobservaciones As String) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosInsertar"
          oraCommandDocumentos.Parameters.Add("pnidDocumento", pnidDocumento)
          oraCommandDocumentos.Parameters.Add("pfecha_Inicio", pfecha_Inicio)
          oraCommandDocumentos.Parameters.Add("pfecha_Fin", pfecha_Fin)
          oraCommandDocumentos.Parameters.Add("pnidEmpEmisora", pnidEmpEmisora)
          oraCommandDocumentos.Parameters.Add("pnidEmpEjecutora", pnidEmpEjecutora)
          oraCommandDocumentos.Parameters.Add("parea", parea)
          oraCommandDocumentos.Parameters.Add("pubicacion", pubicacion)
          oraCommandDocumentos.Parameters.Add("pproposito", pproposito)
          oraCommandDocumentos.Parameters.Add("pnum_Permiso", pnum_Permiso)
          oraCommandDocumentos.Parameters.Add("poxigeno", poxigeno)
          oraCommandDocumentos.Parameters.Add("phidrocarburos", phidrocarburos)
          oraCommandDocumentos.Parameters.Add("pgasesToxicos", pgasesToxicos)
          oraCommandDocumentos.Parameters.Add("pprueba_API", pprueba_API)
          oraCommandDocumentos.Parameters.Add("pprueba_Contratista", pprueba_Contratista)
          oraCommandDocumentos.Parameters.Add("psuperintendente", psuperintendente)
          oraCommandDocumentos.Parameters.Add("presponsable", presponsable)
          oraCommandDocumentos.Parameters.Add("pautorizado_API", pautorizado_API)
          oraCommandDocumentos.Parameters.Add("pFecha_Termino", pFecha_Termino)
          oraCommandDocumentos.Parameters.Add("paprobado", paprobado)
          oraCommandDocumentos.Parameters.Add("pejecutor", pejecutor)
          oraCommandDocumentos.Parameters.Add("pobservaciones", pobservaciones)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function

    ''' <summary>
    ''' Funcion para Modificar un regristro en la tabla Espacios_Confinados
    ''' </summary>
   Public Function Espacios_Confinados_Modificar(pnidDocumento As Long, pfecha_Inicio As String, pfecha_Fin As String, pnidEmpEmisora As Long, pnidEmpEjecutora As Long, parea As String, pubicacion As String, pproposito As String, pnum_Permiso As Long, poxigeno As Double, phidrocarburos As Double, pgasesToxicos As Double, pprueba_API As String, pprueba_Contratista As String, psuperintendente As String, presponsable As String, pautorizado_API As String, pFecha_Termino As String, paprobado As Integer, pejecutor As String, pobservaciones As String) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosModificar"
          oraCommandDocumentos.Parameters.Add("pnidDocumento", pnidDocumento)
          oraCommandDocumentos.Parameters.Add("pfecha_Inicio", pfecha_Inicio)
          oraCommandDocumentos.Parameters.Add("pfecha_Fin", pfecha_Fin)
          oraCommandDocumentos.Parameters.Add("pnidEmpEmisora", pnidEmpEmisora)
          oraCommandDocumentos.Parameters.Add("pnidEmpEjecutora", pnidEmpEjecutora)
          oraCommandDocumentos.Parameters.Add("parea", parea)
          oraCommandDocumentos.Parameters.Add("pubicacion", pubicacion)
          oraCommandDocumentos.Parameters.Add("pproposito", pproposito)
          oraCommandDocumentos.Parameters.Add("pnum_Permiso", pnum_Permiso)
          oraCommandDocumentos.Parameters.Add("poxigeno", poxigeno)
          oraCommandDocumentos.Parameters.Add("phidrocarburos", phidrocarburos)
          oraCommandDocumentos.Parameters.Add("pgasesToxicos", pgasesToxicos)
          oraCommandDocumentos.Parameters.Add("pprueba_API", pprueba_API)
          oraCommandDocumentos.Parameters.Add("pprueba_Contratista", pprueba_Contratista)
          oraCommandDocumentos.Parameters.Add("psuperintendente", psuperintendente)
          oraCommandDocumentos.Parameters.Add("presponsable", presponsable)
          oraCommandDocumentos.Parameters.Add("pautorizado_API", pautorizado_API)
          oraCommandDocumentos.Parameters.Add("pFecha_Termino", pFecha_Termino)
          oraCommandDocumentos.Parameters.Add("paprobado", paprobado)
          oraCommandDocumentos.Parameters.Add("pejecutor", pejecutor)
          oraCommandDocumentos.Parameters.Add("pobservaciones", pobservaciones)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
    ''' <summary>
    ''' Funcion para generar un combo de la tabla Espacios_Confinados
    ''' </summary>
    ''' <param name="pNombre">nombre a buscar en la tabla</param>
    ''' <returns>DataTable</returns>
    ''' <remarks>si el nombre es "" retornara todos los registros</remarks>
   Public Function Espacios_Confinados_Combo(pNombre As String) As DataTable
        Dim dtResultado As New DataTable("Espacios_ConfinadosCombo")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosCombo"
                    oraCommandDocumentos.Parameters.Add("pNombre", pNombre)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para generar la integracion del documento de la tabla Espacios_Confinados
    ''' </summary>
    ''' <param name="pNidDocumento">numero del documento</param>
    ''' <returns>Byte</returns>
    ''' <remarks></remarks>
   Public Function Espacios_Confinados_Integracion(pNidDocumento As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosIntegracion"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
   Public Function Espacios_Confinados_Borrar(pnid As Long) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.Espacios_ConfinadosBorrar"
                    oraCommandDocumentos.Parameters.Add("pnid", pnid)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
  
End Class
